window.addEventListener("load",function () {

    var screen = document.getElementById('screen');

    var cm = new CommentManager(screen);

    cm.init();

    cm.options.global.scale = 2;

    cm.start();

    var time = 0;

    cm.time(time);

    setInterval(function(){
        cm.time(++time * 1000);
    }, 1000);

    window.addEventListener("resize",function () {
        cm.setBounds(screen.offsetWidth, screen.offsetHeight);
    })

    dmsocket.init("fabuhuidanmu");

    dmsocket.onmessage(function(data){
        switch(data.type){
            case 1:
                cm.insert({
                    stime: (time + 1) * 1000,
                    color: 00000000,
                    mode : 1,
                    text : data.data.content,
                    border: false,
                    position: 'absolute',
                });
                break;
        }
    });

    screen.addEventListener("dblclick",function () {
        if(checkFullScreen()){
            exitFullScreen();
        }else{
            fullScreen();
        }
    })

    function fullScreen(){
        if (screen.requestFullscreen) { 
            screen.requestFullscreen(); 
        }
        else if (screen.mozRequestFullScreen) { 
            screen.mozRequestFullScreen();
        }
        else if (screen.webkitRequestFullScreen) { 
            screen.webkitRequestFullScreen(); 
        }
        else if (screen.msRequestFullscreen) {
            screen.msRequestFullscreen();
        }
    }

    function exitFullScreen(){
         if (document.exitFullscreen) { 
            document.exitFullscreen(); 
        } 
        else if (document.mozCancelFullScreen) { 
            document.mozCancelFullScreen(); 
        } 
        else if (document.webkitCancelFullScreen) { 
            document.webkitCancelFullScreen(); 
        } 
        else if (document.msExitFullscreen) { 
            document.msExitFullscreen(); 
        }
    }

    function checkFullScreen(){
        return document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement;
    }
})